package com.example.nio.security.dmo;

import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 前后端交互
 */
@Data
@Builder
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private Long code = 0L;
    private Long count;
    private Integer state = 200;//状态
    private String msg = "请求成功";
    private T data;

    public static final int SUCCESS = 200;//请求通过
    public static final int ERROR_BAD_REQUEST = 400;//请求无效
    public static final int ERROR_FORBIDDEN = 403;//禁止访问
    public static final int ERROR_NOT_FOUND = 404;//无法找到文件
    public static final int ERROR_METHOD_NOT_ALLOWED = 405;//资源被禁止
    public static final int ERROR_TIMEOUT = 408;//请求超时
    public static final int ERROR_SERVER = 500;//服务器异常


    public static Result ok(){
        return ok(null);
    }

    public static Result ok(Object data){
        return new Result().setData(data);
    }

    public static Result error(int state,String msg){
        return new Result().setState(state).setMsg(msg);
    }

    public static Result error(int state,String msg,Object data){
        return new Result().setState(state).setMsg(msg).setData(data);
    }

}

